/*
 * El PC
 *
 * This is part of the game The Rooms
 * Copyright (C) 2010  Elvio Sarquis
 *
 * Get the GNU GPL v3 in http://www.gnu.org/licenses/
 */
package rooms;

import rooms.items.*;

/**
 *
 * @author dask
 */
public class PC extends Character {

    private Item[] invent;
    private Item[] equiped;

    public PC() {

        super(1, 1, '@', "Nombracio", "Human", C.WHITE, 10, 6, 6, 5, 6);

        equiped = new Item[14];
        invent = new Item[0];
    }

    public Item getEquipedItem(int slot) {
        return equiped[slot];
    }

    public Item[] getEquiped() {
        return equiped;
    }

    public Item[] getInvent() {
        return invent;
    }

    public boolean equip(Item what, int where) {
        if (what.isArmour()) {
            Armor item = (Armor) what;

            switch (item.getKind()) {

                case C.HEAD:
                    if (item.getKind() != C.HEAD) {
                        return false;
                    }
                    equiped[C.HEAD] = what;
                    break;

                case C.BODY:
                    if (item.getKind() != C.BODY) {
                        return false;
                    }
                    equiped[C.HEAD] = what;
                    break;
            }
        } else if (what.isWeapon()) {

            if (where != C.RHAND) {
                return false;
            }
            equiped[C.RHAND] = what;
        }
        return true;
    }

    public boolean addIvent(Item what){

        Item[] temp = new Item[invent.length + 1];

        for(int i = 0; i < invent.length; i++)
            temp[i] = invent[i];

        invent = temp;
        invent[invent.length-1] = what;

        return true;
    }

    public void removeItem(int index){

        Item[] tempo = new Item[invent.length - 1];

        for(int i = 0 ; i < invent.length ; i++) {

            if(i < index){
                tempo[i] = invent[i];
            }else if(i > index){
                tempo[i-1] = invent[i];
            }
        }
        invent = new Item[tempo.length];

        for(int i = 0 ; i < tempo.length ; i++) {
            invent[i] = tempo[i];
        }
    }
}
